from rest_framework import serializers
from orders.models import *
from goods.models import *


class OrderSerializer(serializers.ModelSerializer):
    class Meta:
        model = OrderInfo
        fields = [
            'order_id',
            'create_time'
        ]


class SKUSerializer(serializers.ModelSerializer):
    class Meta:
        model = SKU
        fields = ['name', 'default_image']


class OrderGoodsSerializer(serializers.ModelSerializer):
    sku = SKUSerializer(read_only=True)

    class Meta:
        model = OrderGoods
        fields = ['count', 'price', 'sku']


class OrdersSerializer(serializers.ModelSerializer):
    skus = OrderGoodsSerializer(read_only=True, many=True)
    user = serializers.StringRelatedField(read_only=True)
    # status = serializers.IntegerField()
    # order_id = serializers.IntegerField()

    class Meta:
        model = OrderInfo
        fields = '__all__'

